const productsDao = require("../dao/productsDao");

exports.getList = async (req, res) => {
  const products = await productsDao.getAll();
  res.json(products);
};

exports.add = async (req, res) => {
  const product = req.body;
  const result = await productsDao.add(product);
  res.json({ code: 200, message: "添加成功", product: result });
};

exports.update = async (req, res) => {
  const { id } = req.params;
  const product = req.body;
  const result = await productsDao.update(id, product);
  res.json({ code: 200, message: "更新成功", product: result });
};

exports.remove = async (req, res) => {
  const { id } = req.params;
  await productsDao.remove(id);
  res.json({ code: 200, message: "删除成功" });
};
